﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using StructureMap.Configuration.DSL;

namespace DBMigrator.Core.Execution
{
    public class ExecutionRegistry : Registry
    {
        private readonly Assembly assemblyContainingMigrations;

        public ExecutionRegistry(Assembly assemblyContainingMigrations)
        {
            this.assemblyContainingMigrations = assemblyContainingMigrations;
        }

        protected override void configure()
        {
            ForRequestedType<IDownMigrationExecutor>().TheDefault.Is.OfConcreteType<DownMigrationExecutor>();
            ForRequestedType<IExecutableMigration>().TheDefault.Is.OfConcreteType<ExecutableMigration>();
            ForRequestedType<IMigrationExecutor>().TheDefault.Is.OfConcreteType<MigrationExecutor>();
            ForRequestedType<IMigrationLocator>().TheDefault.Is.OfConcreteType<MigrationLocator>()
                .WithCtorArg("assemblyContainingMigrations").EqualTo(assemblyContainingMigrations);
            ForRequestedType<IUpMigrationExecutor>().TheDefault.Is.OfConcreteType<UpMigrationExecutor>();
            ForRequestedType<IVersionManager>().TheDefault.Is.OfConcreteType<VersionManager>();
        }
    }
}
